﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Infinity.Types.Extensions
{
	public static class LazySetExtension
	{
		public static LazySet<T> ToLazySet<T>(this IEnumerable<T> enumerable, Func<T, T> expression, Func<T, bool> condition)
		{
			return new LazySet<T>(expression, enumerable, condition);
		}

		public static LazySet<T> ToLazySet<T>(this IEnumerable<T> enumerable, Func<T, bool> condition)
		{
			return ToLazySet<T>(enumerable, x => x, condition);
		}

		public static LazySet<T> Union<T>(this LazySet<T> first, LazySet<T> second)
		{
			LazySet<T> lazySet = new LazySet<T>(first.Domain.Union(second.Domain), x => first.Condition(x) || second.Condition(x));
			return lazySet;
		}

		public static LazySet<T> Intersect<T>(this LazySet<T> first, LazySet<T> second)
		{
			LazySet<T> lazySet = new LazySet<T>(first.Domain.Intersect(second.Domain),
			                                    x => first.Condition(x) && second.Condition(x));
			return lazySet;
		}

		public static LazySet<T> Except<T>(this LazySet<T> first, LazySet<T> second)
		{
			LazySet<T> lazySet = new LazySet<T>(first.Domain.Except(second.Domain),
			                                    x => first.Condition(x) && !second.Condition(x));
			return lazySet;
		}
	}
}